Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the following recursive C function.v... Start Learning for Free
Consider the following recursive C function.
void get(int n)
{
if (n<1) return;
get (n-1);
get (n-3);    
printf("%d", n);
}
If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?
  • a)
    15
  • b)
    25
  • c)
    35
  • d)
    45
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
Consider the following recursive C function.void get(int n){if (n<...
T(n) = T(n-1) + T(n-3) + 2, here T(n) denotes the number of times a recursive call is made for input n. 2 denotes the two direct recursive calls.
T(n<=0) = 0
T(1) = 2
T(2) = 4
T(3) = 6
T(4) = 10
T(5) = 16
T(6) = 24
So, answer is 24 + 1 call from main = 25.
View all questions of this test
Most Upvoted Answer
Consider the following recursive C function.void get(int n){if (n<...
The given recursive C function `get(int n)` prints the value of `n` in a specific order. Let's break down the function and analyze its behavior to determine how many times it will be invoked before returning to `main()` when `get(6)` is called.

Recursive Function Analysis:
1. If `n` is equal to 1, the function immediately returns.
2. Otherwise, the function calls itself twice with different parameters:
a. `get(n-1)`
b. `get(n-3)`
3. Finally, the function prints the value of `n`.

Function Invocation Analysis:
1. The initial call is `get(6)` from `main()`. So, the function is invoked for the first time.
2. Inside `get(6)`, the first recursive call is `get(6-1)`, which means `get(5)` is invoked.
3. Inside `get(5)`, the first recursive call is `get(5-1)`, which means `get(4)` is invoked.
4. Inside `get(4)`, the first recursive call is `get(4-1)`, which means `get(3)` is invoked.
5. Inside `get(3)`, the first recursive call is `get(3-1)`, which means `get(2)` is invoked.
6. Inside `get(2)`, the first recursive call is `get(2-1)`, which means `get(1)` is invoked.
7. Inside `get(1)`, the function immediately returns without any further recursive calls.
8. Now, the control goes back to the previous stack frame, which was `get(2)`.
9. Inside `get(2)`, the second recursive call is `get(2-3)`, which means `get(-1)` is invoked. However, since `n` is negative, this call does not execute any further recursive calls or printing.
10. The control goes back to the previous stack frame, which was `get(3)`.
11. Inside `get(3)`, the second recursive call is `get(3-3)`, which means `get(0)` is invoked.
12. Inside `get(0)`, the function immediately returns without any further recursive calls.
13. The control goes back to the previous stack frame, which was `get(3)`.
14. Finally, inside `get(3)`, the function prints the value 3.
15. The control goes back to the previous stack frame, which was `get(4)`.
16. Inside `get(4)`, the second recursive call is `get(4-3)`, which means `get(1)` is invoked.
17. Inside `get(1)`, the function immediately returns without any further recursive calls.
18. The control goes back to the previous stack frame, which was `get(4)`.
19. Finally, inside `get(4)`, the function prints the value 4.
20. The control goes back to the previous stack frame, which was `get(5)`.
21. Inside `get(5)`, the second recursive call is `get(5-3)`, which means `get(2)` is invoked.
22. Inside `get(2)`, the first recursive call is `get(2-1)`,
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Question Description
Consider the following recursive C function.void get(int n){if (n<1) return;get (n-1);get (n-3); printf("%d", n);}If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?a)15b)25c)35d)45Correct answer is option 'B'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider the following recursive C function.void get(int n){if (n<1) return;get (n-1);get (n-3); printf("%d", n);}If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?a)15b)25c)35d)45Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following recursive C function.void get(int n){if (n<1) return;get (n-1);get (n-3); printf("%d", n);}If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?a)15b)25c)35d)45Correct answer is option 'B'. Can you explain this answer?.
Solutions for Consider the following recursive C function.void get(int n){if (n<1) return;get (n-1);get (n-3); printf("%d", n);}If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?a)15b)25c)35d)45Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider the following recursive C function.void get(int n){if (n<1) return;get (n-1);get (n-3); printf("%d", n);}If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?a)15b)25c)35d)45Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following recursive C function.void get(int n){if (n<1) return;get (n-1);get (n-3); printf("%d", n);}If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?a)15b)25c)35d)45Correct answer is option 'B'. Can you explain this answer?, a detailed solution for Consider the following recursive C function.void get(int n){if (n<1) return;get (n-1);get (n-3); printf("%d", n);}If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?a)15b)25c)35d)45Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of Consider the following recursive C function.void get(int n){if (n<1) return;get (n-1);get (n-3); printf("%d", n);}If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?a)15b)25c)35d)45Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following recursive C function.void get(int n){if (n<1) return;get (n-1);get (n-3); printf("%d", n);}If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?a)15b)25c)35d)45Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev